import { FC, useEffect } from 'react';
import { QuestionInputPropsType } from './interface';
import { Form, Input } from 'antd';

const PropComponent: FC<QuestionInputPropsType> = (props: QuestionInputPropsType) => {
  const { title, placeholder, onChange, disabled } = props;
  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue({ title, placeholder });
  }, [title, placeholder]);

  function handleValueChange(_: QuestionInputPropsType, allValues: QuestionInputPropsType) {
    console.log(allValues);
    if (onChange) {
      onChange(allValues);
    }
  }
  return (
    <Form
      form={form}
      layout="vertical"
      disabled={disabled}
      initialValues={{ title, placeholder }}
      onValuesChange={handleValueChange}
    >
      <Form.Item label="标题" name="title" rules={[{ required: true, message: '标题不能为空' }]}>
        <Input />
      </Form.Item>
      <Form.Item label="Placeholder" name="placeholder">
        <Input />
      </Form.Item>
    </Form>
  );
};
export default PropComponent;
